package com.css.fxfzxczh.modules.disasterSituationDataManage.samPoiHouSur.verify;

import cn.afterturn.easypoi.excel.entity.result.ExcelVerifyHandlerResult;
import cn.afterturn.easypoi.handler.inter.IExcelVerifyHandler;
import com.css.fxfzxczh.base.dict.repository.entity.DictItemEntity;
import com.css.fxfzxczh.base.dict.service.DictService;
import com.css.fxfzxczh.modules.disasterSituationDataManage.samPoiHouSur.vo.SamPoiHouSurExcelVo;
import com.css.fxfzxczh.util.PlatformObjectUtils;
import com.css.fxfzxczh.zcpt.sys.service.SysAreaService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.net.URLEncoder;
import java.util.ArrayList;
import java.util.List;

@Component
public class SamPoiHouSurExcelVerifyHandler implements IExcelVerifyHandler<SamPoiHouSurExcelVo> {

    @Autowired
    SysAreaService sysAreaService;
    @Autowired
    DictService dictService;

    @Override
    public ExcelVerifyHandlerResult verifyHandler(SamPoiHouSurExcelVo samPoiHouSurExcelVo) {
        ExcelVerifyHandlerResult result = new ExcelVerifyHandlerResult(true);
        StringBuilder message = new StringBuilder("");

        if (!PlatformObjectUtils.isEmpty(samPoiHouSurExcelVo.getProvince()) && !PlatformObjectUtils.isEmpty(samPoiHouSurExcelVo.getCity())  && !PlatformObjectUtils.isEmpty(samPoiHouSurExcelVo.getArea())) {
            String divisionIds = null;
            try {
                divisionIds = sysAreaService.getIdByCondition(URLEncoder.encode(samPoiHouSurExcelVo.getProvince(),"utf-8"),URLEncoder.encode(samPoiHouSurExcelVo.getCity(),"utf-8"),URLEncoder.encode(samPoiHouSurExcelVo.getArea(),"utf-8"));
            } catch (Exception e){

            }
            if (PlatformObjectUtils.isEmpty(divisionIds)) {
                result.setSuccess(false);
                message.append("省市区县名称 不符合规范！");
            }
        }else{
            if (PlatformObjectUtils.isEmpty(samPoiHouSurExcelVo.getProvince())) {
                result.setSuccess(false);
                message.append("省 不能为空！");
            }
            if (PlatformObjectUtils.isEmpty(samPoiHouSurExcelVo.getCity())) {
                result.setSuccess(false);
                message.append("市 不能为空！");
            }
            if (PlatformObjectUtils.isEmpty(samPoiHouSurExcelVo.getArea())) {
                result.setSuccess(false);
                message.append("县 不能为空！");
            }
        }

        if (PlatformObjectUtils.isEmpty(samPoiHouSurExcelVo.getAddress())) {
            result.setSuccess(false);
            message.append("详细地址 不能为空！");
        }

        if (PlatformObjectUtils.isEmpty(samPoiHouSurExcelVo.getLongitude())) {
            result.setSuccess(false);
            message.append("经度 不能为空！");
        }
        if (PlatformObjectUtils.isEmpty(samPoiHouSurExcelVo.getLatitude())) {
            result.setSuccess(false);
            message.append("纬度 不能为空！");
        }


        int type=0;
        int type1=0;
        int type2=0;
        int type3=0;
        int type4=0;
        int type5=0;
        int type6=0;
        int type7=0;
        int type8=0;
        int type9=0;
        int flag=0;
        //I类 II类 III-1类 III-2类 Ⅳ类 V-1类 V-2类 V-3类 Ⅵ类 Ⅶ类
        if (PlatformObjectUtils.isNotEmpty(samPoiHouSurExcelVo.getDestroy())) {
            Integer destroy = samPoiHouSurExcelVo.getDestroy();
            boolean checked = checkNum(result, message, destroy.toString(), "I类-毁坏");
            if (checked){
                type++;
            }
        }
        if (PlatformObjectUtils.isNotEmpty(samPoiHouSurExcelVo.getSeriousDamage())) {
            Integer seriousDamage = samPoiHouSurExcelVo.getSeriousDamage();
            boolean checked = checkNum(result, message, seriousDamage.toString(), "I类-严重破坏");
            if (checked){
                type++;
            }
        }
        if (PlatformObjectUtils.isNotEmpty(samPoiHouSurExcelVo.getModerateDamage()) ) {
            Integer moderateDamage = samPoiHouSurExcelVo.getModerateDamage();
            boolean checked = checkNum(result, message, moderateDamage.toString(), "I类-中等破坏");
            if (checked){
                type++;
            }
        }
        if (PlatformObjectUtils.isNotEmpty(samPoiHouSurExcelVo.getMinorDamage())) {
            Integer minorDamage = samPoiHouSurExcelVo.getMinorDamage();
            boolean checked = checkNum(result, message, minorDamage.toString(), "I类-轻微破坏");
            if (checked){
                type++;
            }
        }
        if (PlatformObjectUtils.isNotEmpty(samPoiHouSurExcelVo.getBasicallyIntact())) {
            Integer basicallyIntact = samPoiHouSurExcelVo.getBasicallyIntact();
            boolean checked = checkNum(result, message, basicallyIntact.toString(), "I类-基本完好");
            if (checked){
                type++;
            }
        }
        if(type==0){
            flag++;
        }else{
            if(type!=5){
                result.setSuccess(false);
                message.append("I类破坏程度未填写完成!");
            }
        }
        //II类
        if (PlatformObjectUtils.isNotEmpty(samPoiHouSurExcelVo.getDestroy1())) {
            Integer destroy1 = samPoiHouSurExcelVo.getDestroy1();
            boolean checked = checkNum(result, message, destroy1.toString(), "II类-毁坏");
            if (checked){
                type1++;
            }
        }
        if (PlatformObjectUtils.isNotEmpty(samPoiHouSurExcelVo.getSeriousDamage1())) {
            Integer seriousDamage1 = samPoiHouSurExcelVo.getSeriousDamage1();
            boolean checked = checkNum(result, message, seriousDamage1.toString(), "II类-严重破坏");
            if (checked){
                type1++;
            }
        }
        if (PlatformObjectUtils.isNotEmpty(samPoiHouSurExcelVo.getModerateDamage1()) ) {
            Integer moderateDamage1 = samPoiHouSurExcelVo.getModerateDamage1();
            boolean checked = checkNum(result, message, moderateDamage1.toString(), "II类-中等破坏");
            if (checked){
                type1++;
            }
        }
        if (PlatformObjectUtils.isNotEmpty(samPoiHouSurExcelVo.getMinorDamage1())) {
            Integer minorDamage1 = samPoiHouSurExcelVo.getMinorDamage1();
            boolean checked = checkNum(result, message, minorDamage1.toString(), "II类-轻微破坏");
            if (checked){
                type1++;
            }
        }
        if (PlatformObjectUtils.isNotEmpty(samPoiHouSurExcelVo.getBasicallyIntact1())) {
            Integer basicallyIntact1 = samPoiHouSurExcelVo.getBasicallyIntact1();
            boolean checked = checkNum(result, message, basicallyIntact1.toString(), "II类-基本完好");
            if (checked){
                type1++;
            }
        }
        if(type1==0){
            flag++;
        }else{
            if(type1!=5){
                result.setSuccess(false);
                message.append("II类破坏程度未填写完成!");
            }
        }
        //III-1类
        if (PlatformObjectUtils.isNotEmpty(samPoiHouSurExcelVo.getDestroy2())) {
            Integer destroy2 = samPoiHouSurExcelVo.getDestroy2();
            boolean checked = checkNum(result, message, destroy2.toString(), "III-1类-毁坏");
            if (checked){
                type2++;
            }
        }
        if (PlatformObjectUtils.isNotEmpty(samPoiHouSurExcelVo.getSeriousDamage2())) {
            Integer seriousDamage2 = samPoiHouSurExcelVo.getSeriousDamage2();
            boolean checked = checkNum(result, message, seriousDamage2.toString(), "III-1类-严重破坏");
            if (checked){
                type2++;
            }
        }
        if (PlatformObjectUtils.isNotEmpty(samPoiHouSurExcelVo.getModerateDamage2()) ) {
            Integer moderateDamage2 = samPoiHouSurExcelVo.getModerateDamage2();
            boolean checked = checkNum(result, message, moderateDamage2.toString(), "III-1类-中等破坏");
            if (checked){
                type2++;
            }
        }
        if (PlatformObjectUtils.isNotEmpty(samPoiHouSurExcelVo.getMinorDamage2())) {
            Integer minorDamage2 = samPoiHouSurExcelVo.getMinorDamage2();
            boolean checked = checkNum(result, message, minorDamage2.toString(), "III-1类-轻微破坏");
            if (checked){
                type2++;
            }
        }
        if (PlatformObjectUtils.isNotEmpty(samPoiHouSurExcelVo.getBasicallyIntact2())) {
            Integer basicallyIntact2 = samPoiHouSurExcelVo.getBasicallyIntact2();
            boolean checked = checkNum(result, message, basicallyIntact2.toString(), "III-1类-基本完好");
            if (checked){
                type2++;
            }
        }
        if(type2==0){
            flag++;
        }else{
            if(type2!=5){
                result.setSuccess(false);
                message.append("III-1类破坏程度未填写完成!");
            }
        }
        //III-2类
        if (PlatformObjectUtils.isNotEmpty(samPoiHouSurExcelVo.getDestroy3())) {
            Integer destroy3 = samPoiHouSurExcelVo.getDestroy3();
            boolean checked = checkNum(result, message, destroy3.toString(), "III-2类-毁坏");
            if (checked){
                type3++;
            }
        }
        if (PlatformObjectUtils.isNotEmpty(samPoiHouSurExcelVo.getSeriousDamage3())) {
            Integer seriousDamage3 = samPoiHouSurExcelVo.getSeriousDamage3();
            boolean checked = checkNum(result, message, seriousDamage3.toString(), "III-2类-严重破坏");
            if (checked){
                type3++;
            }
        }
        if (PlatformObjectUtils.isNotEmpty(samPoiHouSurExcelVo.getModerateDamage3()) ) {
            Integer moderateDamage3 = samPoiHouSurExcelVo.getModerateDamage3();
            boolean checked = checkNum(result, message, moderateDamage3.toString(), "III-2类-中等破坏");
            if (checked){
                type3++;
            }
        }
        if (PlatformObjectUtils.isNotEmpty(samPoiHouSurExcelVo.getMinorDamage3())) {
            Integer minorDamage3 = samPoiHouSurExcelVo.getMinorDamage3();
            boolean checked = checkNum(result, message, minorDamage3.toString(), "III-2类-轻微破坏");
            if (checked){
                type3++;
            }
        }
        if (PlatformObjectUtils.isNotEmpty(samPoiHouSurExcelVo.getBasicallyIntact3())) {
            Integer basicallyIntact3 = samPoiHouSurExcelVo.getBasicallyIntact3();
            boolean checked = checkNum(result, message, basicallyIntact3.toString(), "III-2类-基本完好");
            if (checked){
                type3++;
            }
        }
        if(type3==0){
            flag++;
        }else{
            if(type3!=5){
                result.setSuccess(false);
                message.append("III-2类破坏程度未填写完成!");
            }
        }
        //Ⅳ类
        if (PlatformObjectUtils.isNotEmpty(samPoiHouSurExcelVo.getDestroy4())) {
            Integer destroy4 = samPoiHouSurExcelVo.getDestroy4();
            boolean checked = checkNum(result, message, destroy4.toString(), "Ⅳ类-毁坏");
            if (checked){
                type4++;
            }
        }
        if (PlatformObjectUtils.isNotEmpty(samPoiHouSurExcelVo.getSeriousDamage4())) {
            Integer seriousDamage4 = samPoiHouSurExcelVo.getSeriousDamage4();
            boolean checked = checkNum(result, message, seriousDamage4.toString(), "Ⅳ类-严重破坏");
            if (checked){
                type4++;
            }
        }
        if (PlatformObjectUtils.isNotEmpty(samPoiHouSurExcelVo.getModerateDamage4()) ) {
            Integer moderateDamage4 = samPoiHouSurExcelVo.getModerateDamage4();
            boolean checked = checkNum(result, message, moderateDamage4.toString(), "Ⅳ类-中等破坏");
            if (checked){
                type4++;
            }
        }
        if (PlatformObjectUtils.isNotEmpty(samPoiHouSurExcelVo.getMinorDamage4())) {
            Integer minorDamage4 = samPoiHouSurExcelVo.getMinorDamage4();
            boolean checked = checkNum(result, message, minorDamage4.toString(), "Ⅳ类-轻微破坏");
            if (checked){
                type4++;
            }
        }
        if (PlatformObjectUtils.isNotEmpty(samPoiHouSurExcelVo.getBasicallyIntact4())) {
            Integer basicallyIntact4 = samPoiHouSurExcelVo.getBasicallyIntact4();
            boolean checked = checkNum(result, message, basicallyIntact4.toString(), "Ⅳ类-基本完好");
            if (checked){
                type4++;
            }
        }
        if(type4==0){
            flag++;
        }else{
            if(type4!=5){
                result.setSuccess(false);
                message.append("Ⅳ类破坏程度未填写完成!");
            }
        }
        //V-1类
        if (PlatformObjectUtils.isNotEmpty(samPoiHouSurExcelVo.getDestroy5())) {
            Integer destroy5 = samPoiHouSurExcelVo.getDestroy5();
            boolean checked = checkNum(result, message, destroy5.toString(), "V-1类-毁坏");
            if (checked){
                type5++;
            }
        }
        if (PlatformObjectUtils.isNotEmpty(samPoiHouSurExcelVo.getSeriousDamage5())) {
            Integer seriousDamage5 = samPoiHouSurExcelVo.getSeriousDamage5();
            boolean checked = checkNum(result, message, seriousDamage5.toString(), "V-1类-严重破坏");
            if (checked){
                type5++;
            }
        }
        if (PlatformObjectUtils.isNotEmpty(samPoiHouSurExcelVo.getModerateDamage5()) ) {
            Integer moderateDamage5 = samPoiHouSurExcelVo.getModerateDamage5();
            boolean checked = checkNum(result, message, moderateDamage5.toString(), "V-1类-中等破坏");
            if (checked){
                type5++;
            }
        }
        if (PlatformObjectUtils.isNotEmpty(samPoiHouSurExcelVo.getMinorDamage5())) {
            Integer minorDamage5 = samPoiHouSurExcelVo.getMinorDamage5();
            boolean checked = checkNum(result, message, minorDamage5.toString(), "V-1类-轻微破坏");
            if (checked){
                type5++;
            }
        }
        if (PlatformObjectUtils.isNotEmpty(samPoiHouSurExcelVo.getBasicallyIntact5())) {
            Integer basicallyIntact5 = samPoiHouSurExcelVo.getBasicallyIntact5();
            boolean checked = checkNum(result, message, basicallyIntact5.toString(), "V-1类-基本完好");
            if (checked){
                type5++;
            }
        }
        if(type5==0){
            flag++;
        }else{
            if(type5!=5){
                result.setSuccess(false);
                message.append("V-1类破坏程度未填写完成!");
            }
        }
        //V-2类
        if (PlatformObjectUtils.isNotEmpty(samPoiHouSurExcelVo.getDestroy6())) {
            Integer destroy6 = samPoiHouSurExcelVo.getDestroy6();
            boolean checked = checkNum(result, message, destroy6.toString(), "V-2类-毁坏");
            if (checked){
                type6++;
            }
        }
        if (PlatformObjectUtils.isNotEmpty(samPoiHouSurExcelVo.getSeriousDamage6())) {
            Integer seriousDamage6 = samPoiHouSurExcelVo.getSeriousDamage6();
            boolean checked = checkNum(result, message, seriousDamage6.toString(), "V-2类-严重破坏");
            if (checked){
                type6++;
            }
        }
        if (PlatformObjectUtils.isNotEmpty(samPoiHouSurExcelVo.getModerateDamage6()) ) {
            Integer moderateDamage6 = samPoiHouSurExcelVo.getModerateDamage6();
            boolean checked = checkNum(result, message, moderateDamage6.toString(), "V-2类-中等破坏");
            if (checked){
                type6++;
            }
        }
        if (PlatformObjectUtils.isNotEmpty(samPoiHouSurExcelVo.getMinorDamage6())) {
            Integer minorDamage6 = samPoiHouSurExcelVo.getMinorDamage6();
            boolean checked = checkNum(result, message, minorDamage6.toString(), "V-2类-轻微破坏");
            if (checked){
                type6++;
            }
        }
        if (PlatformObjectUtils.isNotEmpty(samPoiHouSurExcelVo.getBasicallyIntact6())) {
            Integer basicallyIntact6 = samPoiHouSurExcelVo.getBasicallyIntact6();
            boolean checked = checkNum(result, message, basicallyIntact6.toString(), "V-2类-基本完好");
            if (checked){
                type6++;
            }
        }
        if(type6==0){
            flag++;
        }else{
            if(type6!=5){
                result.setSuccess(false);
                message.append("V-2类破坏程度未填写完成!");
            }
        }
        //V-3类
        if (PlatformObjectUtils.isNotEmpty(samPoiHouSurExcelVo.getDestroy7())) {
            Integer destroy7 = samPoiHouSurExcelVo.getDestroy7();
            boolean checked = checkNum(result, message, destroy7.toString(), "V-3类-毁坏");
            if (checked){
                type7++;
            }
        }
        if (PlatformObjectUtils.isNotEmpty(samPoiHouSurExcelVo.getSeriousDamage7())) {
            Integer seriousDamage7 = samPoiHouSurExcelVo.getSeriousDamage7();
            boolean checked = checkNum(result, message, seriousDamage7.toString(), "V-3类-严重破坏");
            if (checked){
                type7++;
            }
        }
        if (PlatformObjectUtils.isNotEmpty(samPoiHouSurExcelVo.getModerateDamage7()) ) {
            Integer moderateDamage7 = samPoiHouSurExcelVo.getModerateDamage7();
            boolean checked = checkNum(result, message, moderateDamage7.toString(), "V-3类-中等破坏");
            if (checked){
                type7++;
            }
        }
        if (PlatformObjectUtils.isNotEmpty(samPoiHouSurExcelVo.getMinorDamage7())) {
            Integer minorDamage7 = samPoiHouSurExcelVo.getMinorDamage7();
            boolean checked = checkNum(result, message, minorDamage7.toString(), "V-3类-轻微破坏");
            if (checked){
                type7++;
            }
        }
        if (PlatformObjectUtils.isNotEmpty(samPoiHouSurExcelVo.getBasicallyIntact7())) {
            Integer basicallyIntact7 = samPoiHouSurExcelVo.getBasicallyIntact7();
            boolean checked = checkNum(result, message, basicallyIntact7.toString(), "V-3类-基本完好");
            if (checked){
                type7++;
            }
        }
        if(type7==0){
            flag++;
        }else{
            if(type7!=5){
                result.setSuccess(false);
                message.append("V-3类破坏程度未填写完成!");
            }
        }
        //Ⅵ类
        if (PlatformObjectUtils.isNotEmpty(samPoiHouSurExcelVo.getDestroy8())) {
            Integer destroy8 = samPoiHouSurExcelVo.getDestroy8();
            boolean checked = checkNum(result, message, destroy8.toString(), "Ⅵ类-毁坏");
            if (checked){
                type8++;
            }
        }
        if (PlatformObjectUtils.isNotEmpty(samPoiHouSurExcelVo.getSeriousDamage8())) {
            Integer seriousDamage8 = samPoiHouSurExcelVo.getSeriousDamage8();
            boolean checked = checkNum(result, message, seriousDamage8.toString(), "Ⅵ类-严重破坏");
            if (checked){
                type8++;
            }
        }
        if (PlatformObjectUtils.isNotEmpty(samPoiHouSurExcelVo.getModerateDamage8()) ) {
            Integer moderateDamage8 = samPoiHouSurExcelVo.getModerateDamage8();
            boolean checked = checkNum(result, message, moderateDamage8.toString(), "Ⅵ类-中等破坏");
            if (checked){
                type8++;
            }
        }
        if (PlatformObjectUtils.isNotEmpty(samPoiHouSurExcelVo.getMinorDamage8())) {
            Integer minorDamage8 = samPoiHouSurExcelVo.getMinorDamage8();
            boolean checked = checkNum(result, message, minorDamage8.toString(), "Ⅵ类-轻微破坏");
            if (checked){
                type8++;
            }
        }
        if (PlatformObjectUtils.isNotEmpty(samPoiHouSurExcelVo.getBasicallyIntact8())) {
            Integer basicallyIntact8 = samPoiHouSurExcelVo.getBasicallyIntact8();
            boolean checked = checkNum(result, message, basicallyIntact8.toString(), "Ⅵ类-基本完好");
            if (checked){
                type8++;
            }
        }
        if(type8==0){
            flag++;
        }else{
            if(type8!=5){
                result.setSuccess(false);
                message.append("Ⅵ类破坏程度未填写完成!");
            }
        }
        //Ⅶ类
        if (PlatformObjectUtils.isNotEmpty(samPoiHouSurExcelVo.getDestroy9())) {
            Integer destroy9 = samPoiHouSurExcelVo.getDestroy9();
            boolean checked = checkNum(result, message, destroy9.toString(), "Ⅶ类-毁坏");
            if (checked){
                type9++;
            }
        }
        if (PlatformObjectUtils.isNotEmpty(samPoiHouSurExcelVo.getSeriousDamage9())) {
            Integer seriousDamage9 = samPoiHouSurExcelVo.getSeriousDamage9();
            boolean checked = checkNum(result, message, seriousDamage9.toString(), "Ⅶ类-严重破坏");
            if (checked){
                type9++;
            }
        }
        if (PlatformObjectUtils.isNotEmpty(samPoiHouSurExcelVo.getModerateDamage9()) ) {
            Integer moderateDamage9 = samPoiHouSurExcelVo.getModerateDamage9();
            boolean checked = checkNum(result, message, moderateDamage9.toString(), "Ⅶ类-中等破坏");
            if (checked){
                type9++;
            }
        }
        if (PlatformObjectUtils.isNotEmpty(samPoiHouSurExcelVo.getMinorDamage9())) {
            Integer minorDamage9 = samPoiHouSurExcelVo.getMinorDamage9();
            boolean checked = checkNum(result, message, minorDamage9.toString(), "Ⅶ类-轻微破坏");
            if (checked){
                type9++;
            }
        }
        if (PlatformObjectUtils.isNotEmpty(samPoiHouSurExcelVo.getBasicallyIntact9())) {
            Integer basicallyIntact9 = samPoiHouSurExcelVo.getBasicallyIntact9();
            boolean checked = checkNum(result, message, basicallyIntact9.toString(), "Ⅶ类-基本完好");
            if (checked){
                type9++;
            }
        }
        if(type9==0){
            flag++;
        }else{
            if(type9!=5){
                result.setSuccess(false);
                message.append("Ⅵ类破坏程度未填写完成!");
            }
        }

        if(flag==10){
            result.setSuccess(false);
            message.append("请至少填写一个结构类型下的五个破坏状态的面积!");
        }




        if (!PlatformObjectUtils.isEmpty(samPoiHouSurExcelVo.getTopographicFeatures())) {
            List<String> list = checkData("dxdm");
            if(!list.contains(samPoiHouSurExcelVo.getTopographicFeatures())){
                result.setSuccess(false);
                message.append("地形地貌 不正确！");
            }
        }

        if (!PlatformObjectUtils.isEmpty(samPoiHouSurExcelVo.getPersonnelShock())) {
            List<String> list = checkData("ryzgqk");
            if(!list.contains(samPoiHouSurExcelVo.getPersonnelShock())){
                result.setSuccess(false);
                message.append("人员震感情况 不正确！");
            }
        }

        if (!PlatformObjectUtils.isEmpty(samPoiHouSurExcelVo.getReactionOfVessels())) {
            List<String> list = checkData("qmfyqk");
            if(!list.contains(samPoiHouSurExcelVo.getReactionOfVessels())){
                result.setSuccess(false);
                message.append("器皿反应情况 不正确！");
            }
        }

        if (!PlatformObjectUtils.isEmpty(samPoiHouSurExcelVo.getMacroscopicAnomaly())) {
            List<String> list = checkData("hgycxx");
            for(String str : samPoiHouSurExcelVo.getMacroscopicAnomaly().split("、")){
                if(!list.contains(str)){
                    result.setSuccess(false);
                    message.append("宏观异常现象 不正确！");
                    break;
                }
            }
        }

        if (!PlatformObjectUtils.isEmpty(samPoiHouSurExcelVo.getGeologicHazard())) {
            List<String> list = checkData("dzzh");
            for(String str : samPoiHouSurExcelVo.getGeologicHazard().split("、")){
                if(!list.contains(str)){
                    result.setSuccess(false);
                    message.append("地质灾害 不正确！");
                    break;
                }
            }
        }

        if (!PlatformObjectUtils.isEmpty(samPoiHouSurExcelVo.getBuildingEarthquakeDescription())) {
            List<String> list = checkData("jzwzhtzms");
            for(String str : samPoiHouSurExcelVo.getBuildingEarthquakeDescription().split("、")){
                if(!list.contains(str)){
                    result.setSuccess(false);
                    message.append("建筑物震害特征描述 不正确！");
                    break;
                }
            }
        }


        if (PlatformObjectUtils.isEmpty(samPoiHouSurExcelVo.getIntensityDetermination())) {
            result.setSuccess(false);
            message.append("烈度拟定 不能为空！");
        }else{
            List<String> list = checkData("ldnd");
            List<String> strings = intensityList();
            String intensityDetermination = samPoiHouSurExcelVo.getIntensityDetermination();
            if(!strings.contains(samPoiHouSurExcelVo.getIntensityDetermination())){
                result.setSuccess(false);
                message.append("烈度拟定 不正确！");
            }
        }


        if (PlatformObjectUtils.isNotEmpty(samPoiHouSurExcelVo.getSamplingPointHouseholds())) {
            String str = samPoiHouSurExcelVo.getSamplingPointHouseholds();
            checkNum( result,  message, str,"抽样点户数");
        }

        if (PlatformObjectUtils.isNotEmpty(samPoiHouSurExcelVo.getPerHouseholdArea())) {
            String str = samPoiHouSurExcelVo.getPerHouseholdArea();
            checkNum( result,  message, str,"户均房屋面积");

        }

        if (PlatformObjectUtils.isNotEmpty(samPoiHouSurExcelVo.getSamplingPointPopulation())) {
            String str = samPoiHouSurExcelVo.getSamplingPointPopulation();
            checkNum( result,  message, str,"抽样点人口");
        }


        result.setMsg(message.toString());
        return result;
    }

    private List<String> intensityList(){
        List<String> list = new ArrayList<>();
        list.add("VI度");
        list.add("VII度");
        list.add("VIII度");
        list.add("IX度");
        list.add("X度");
        list.add("XI度");
        list.add("XII度");
        return list;
    }
    private static boolean checkNum(ExcelVerifyHandlerResult result, StringBuilder message,String str,String columnName){
        boolean flag=true;
        try {
            double num = Double.parseDouble(str);
            if (num < 0) {
                flag=false;
                result.setSuccess(false);
                message.append(""+columnName+" 不可小于0！");
            }
        } catch (NumberFormatException e) {
            flag=false;
            result.setSuccess(false);
            message.append(""+columnName+" 不是一个有效的数字!");
        }
        return flag;
    }


    private List<String> checkData(String code){
        List<DictItemEntity> validDictItemsByDictCode = dictService.getValidDictItemsByDictCode(code);
        List<String> list = new ArrayList<>();
        for(DictItemEntity dictItemEntity: validDictItemsByDictCode){
            String dictItemName = dictItemEntity.getDictItemName();
            list.add(dictItemName);
        }
        return list;
    }

}
